<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>药库发药</title>
</head>
<body>
	<div id="medcineManage" class="easyui-tabs"
		style="width: 100%; height: 100%;">
		<div title="发药管理" style="display: none;"
			data-options="iconCls:'icon-add'">
			<div style="width: 100%; height: 100%">
				<div id="ssSendDrugsToolbar" style="padding-left: 5px">
					<input id="searchSSsendDrugsName" name="searchSSsendDrugsName"
						class="easyui-searchbox" data-options="width:200,prompt:'发药总表名称'">
					<span style="padding-left: 10px; font-size: 14px">开始日期</span> <span
						style="padding-left: 5px"> <input id="SSsendDrugsStartDate"
						class="easyui-datebox" data-options="width:120">
					</span> <span style="padding-left: 10px; font-size: 14px">截止日期</span> <span
						style="padding-left: 5px"> <input id="SSsendDrugsEndDate"
						class="easyui-datebox" data-options="width:120">
					</span> <a id="SSsendDrugsSearch" class="easyui-linkbutton"
						data-options="iconCls:'icon-search'">查找</a> <span
						style="padding-left: 10px"> <a id="SSsendDrugsAll_btn"
						class="easyui-linkbutton" data-options="iconCls:'icon-tip'">所有发药</a>
					</span> <span style="padding-left: 220px"> <a
						class="easyui-linkbutton" data-options="iconCls:'icon-add'"
						id="SSSendMedcine_Yes">发药</a>
					</span>
				</div>
				<table id="ssSendDrugsGrid" class="easyui-datagrid"
					style="height: 100%; width: 100%"
					data-options="singleSelect:true,rownumbers:true,fitColumns:true,pagination:true,title:'发药总表',url:'getAllSSsendDrugs',method:'get',toolbar:'#ssSendDrugsToolbar'">
					<thead>
						<tr>
							<th
								data-options="field:'sendmedcineDrugstoreId',width:100,align:'center'">发药编号</th>
							<th
								data-options="field:'sendmedcineName',width:100,align:'center'">发药名称</th>
							<th
								data-options="field:'sendmedcineDate',width:100,align:'center'">最新日期</th>
							<th
								data-options="field:'sendmedcineAllcost',width:100,align:'center'">已发药价格</th>
						</tr>
					</thead>
				</table>
			</div>
			<div id="SSsendDrugsPeopleWin" class="easyui-window" title="发药人" style="width:300px;height:200px;"   
			        data-options="resizable:true,closed:true">   
			    发药人:<select id="SSsendDrugsPeople" class="easyui-combobox" id="SSSendDrugsDetailsWinStaff"
						data-options="width:200,url:'getAllStaff',method:'get',valueField:'staffId',textField:'staffname',panelHeight:'auto',value:1"></select>  
					<a id="SSsendDrugsPeoWinYes" class="easyui-linkbutton" data-options="iconCls:'icon-ok'">确定</a> 
			</div>  
			<!-- 药库发药详情window -->
			<div id="SSSendDrugsDetailsWin" class="easyui-window"
				data-options="draggable:true,resizable:false,iconCls:'icon-add',width:883,height:370,closed:true,title:'发药'">
				<div id="SSSendDrugsDetailsToolbar" style="padding-left: 5px">
					药品类<select class="easyui-combobox" id="SSSendDrugsDetailsWinDtype"
						data-options="url:'getAllMedcineType',width:100,textField:'medcineTypeName',valueField:'medcinetypeId',method:'get',panelHeight:'auto'"></select>
					<span> 药房<select class="easyui-combobox" id="SSSendDrugsDetailsWinDStore"
						data-options="url:'getAllMedcineStore',width:100,textField:'medcinestoreName',valueField:'medcinestoreId',method:'get',panelHeight:'auto'">
					</select>
					</span> <span>发药人<select class="easyui-combobox" id="SSSendDrugsDetailsWinStaff"
						data-options="width:200,url:'getAllStaff',method:'get',valueField:'staffId',textField:'staffname',panelHeight:'auto'"></select>
					</span>
					<span style="padding-left: 20px"> <a id="SsSendDrugsWinGridSearchYes"
						class="easyui-linkbutton" data-options="iconCls:'icon-search'">查询</a>
					</span> 
					<span style="padding-left: 20px"> <a id="SSSendDrugsWinYes"
						class="easyui-linkbutton" data-options="iconCls:'icon-add'">发药</a>
					</span> 
				</div>
				<table class="easyui-datagrid" style="width: 100%; height: 100%"
					id="SsSendDrugsWinGrid"
					data-options="url:'getAllSSsendDrugsDetailsMap',method:'get',title:'发药详情',fitColumns:true,toolbar:'#SSSendDrugsDetailsToolbar',pagination:true,rownumbers:true,singleSelect:true">
					<thead>
						<tr>
							<th
								data-options="field:'sendmedcineDetailsId',width:100,align:'center'">发药编号</th>
							<th
								data-options="field:'sendmedcineName',width:100,align:'center'">批号</th>
							<th data-options="field:'medcineName',width:100,align:'center'">药品名称</th>
							<th
								data-options="field:'sendmedcineNumber',width:100,align:'center'">药品数量</th>
							<th
								data-options="field:'medcinestoreName',width:100,align:'center'">发药药房</th>
							<th data-options="field:'staffname',width:100,align:'center'">发药人</th>
						</tr>
					</thead>
				</table>
			</div>
		</div>
		<div title="发药统计" data-options="iconCls:'icon-add',closable:true"
			style="overflow: auto; display: none;"></div>
		<div title="打印报告" data-options="iconCls:'icon-add',closable:true"
			style="display: none;"></div>
			
	</div>
	<script>
		$(function() {
			$("#SSsendDrugsPeoWinYes").linkbutton({
				onClick : function(){
					var SSsendDrugsPeople =$("#SSsendDrugsPeople").combobox('getValue');
					var row = $("#SsSendDrugsWinGrid").datagrid('getSelected');
					var row2 = $("#ssSendDrugsGrid").datagrid('getSelected');
					$.get('SSselectOneDrugsNumber?medcineName='+row.medcineName,function(v){
						$.messager.confirm('提示',"发药人:"+SSsendDrugsPeople+',药库：'+row.medcineName+"库存是"+"<span style='color:red'>"+v+"</span>,确定要发药<span style='color:red'>"+row.sendmedcineNumber+"</span>吗？",function(r){
							if(r){
								$("#SSsendDrugsPeopleWin").window('close');
								$.get('SSsendDrugsYes?SSsendDrugsPeople='+SSsendDrugsPeople+"&sendmedcineDetailsId="+row.sendmedcineDetailsId+"&medcineNumber="+row.sendmedcineNumber+"&medcineName="+row.medcineName,function(r){
									$("#SsSendDrugsWinGrid").datagrid('reload','getAllSSsendDrugsDetailsMap?sendmedcineDrugstoreId='+row2.sendmedcineDrugstoreId);
								});
								$.messager.alert('提示','发药成功');
							}
						});
					});
				}
			});
			//SsSendDrugsWinGrid绑定基本样式
			//如果这种药还没有发药，背景变红
			$("#SsSendDrugsWinGrid").datagrid({
				rowStyler : function(index,row){
					if(row.staffname==""){
						return 'color:#FF0033;';
					}
				}
			});
			//按条件查询药库发药
			$("#SSsendDrugsSearch").linkbutton(
					{
						onClick : function() {
							var startDate = $("#SSsendDrugsStartDate").datebox(
									'getValue');
							var endDate = $("#SSsendDrugsEndDate").datebox(
									'getValue');
							console.log(startDate + endDate);
							if (startDate != '' || endDate != '') {
								$("#ssSendDrugsGrid").datagrid(
										'load',
										'searchSSSendDrugs?startDate='
												+ startDate + "&endDate="
												+ endDate);
							} else {
								$.messager.alert('提示', '请输入查询条件');
							}
						}
					});
			//所有发药按钮
			$("#SSsendDrugsAll_btn").linkbutton(
					{
						onClick : function() {
							$("#ssSendDrugsGrid").datagrid('load',
									'getAllSSsendDrugs');
							//清空所有的发药条件
							$("#SSsendDrugsStartDate").datebox('setValue', '');
							$("#SSsendDrugsEndDate").datebox('setValue', '');
						}
					});
			//根据名称精准查询某项发药
			$("#searchSSsendDrugsName").searchbox(
					{
						searcher : function(value, name) {
							//searchbox执行一次搜索后要清空
							if (value != '') {
								$("#ssSendDrugsGrid").datagrid(
										'load',
										'searchSSsendDrugsName?searchSSsendDrugsName='
												+ value);
								$("#searchSSsendDrugsName").searchbox(
										'setValue', '');
							} else {
								$.messager.alert('提示', '请先输入结果');
							}
						}
					});
			//发药按钮
			$("#SSSendMedcine_Yes").linkbutton(
					{
						onClick : function() {
							var row = $("#ssSendDrugsGrid").datagrid(
									'getSelected');
							
							if (row != null) {
								console.log("--"+row.sendmedcineDrugstoreId);
								//console.log(row.sendmedcineDrugstoreId);
								$("#SsSendDrugsWinGrid").datagrid(
										'load',
										'getAllSSsendDrugsDetailsMap?sendmedcineDrugstoreId='
												+ row.sendmedcineDrugstoreId);
								$("#SSSendDrugsDetailsWin").window("open");
							} else {
								$.messager.alert('提示', '请选择要操作的行');
							}
						}
					});
			//药库给药房发药yes按钮
			$("#SSSendDrugsWinYes").linkbutton({
				onClick : function(){
					var row = $("#SsSendDrugsWinGrid").datagrid('getSelected');
					if(row!=null){
						if(row.staffname==""){
							$("#SSsendDrugsPeopleWin").window('open');
							
						}else{
							$.messager.alert('提示','请选择未发药的行');
						}
					}else{
						$.messager.alert('提示','请选择你要操作的行');
					}
					
				}
			});
			//按条件查询发药详情
			$("#SsSendDrugsWinGridSearchYes").linkbutton({
				onClick : function(){
					var row = $("#ssSendDrugsGrid").datagrid('getSelected');
					if(row!=null){
						var medcineType = $("#SSSendDrugsDetailsWinDtype").combobox('getValue');
						var medcineStore = $("#SSSendDrugsDetailsWinDStore").combobox('getValue');
						var staff = $("#SSSendDrugsDetailsWinStaff").combobox('getValue');
						$("#SsSendDrugsWinGrid").datagrid('load','getAllSSsendDrugsDetailsMap?medcineType='+medcineType+'&medcineStore='+medcineStore+'&staff='+staff+'&sendmedcineDrugstoreId='+row.sendmedcineDrugstoreId);
						$("#SSSendDrugsDetailsWinDtype").combobox('setValue','');
						$("#SSSendDrugsDetailsWinDStore").combobox('setValue','')
						$("#SSSendDrugsDetailsWinStaff").combobox('setValue','')
					}else{
						$.messager.alert('提示','请选择药库发药总编号');
					}
				}
			});
		});
	</script>
</body>
</html>